import QtQuick
import QtQuick.Controls.Material

Popup {
    id: popUp
    modal: true
    width: parent.width
    height: 100

    background: Rectangle{
        color: "transparent"

        Rectangle{
            height: 1
            width: parent.width
            y : 0
            color: "black"
        }

        Rectangle{
            height: 1
            width: parent.width
            y : parent.height - height
            color: "black"
        }

    }

    Component.onCompleted: {
        Cpp_PLC.warning_Signal_Changed_Sig.connect(warningSignalChanged)
        sequentialAnimation.start()
    }

    // 报警信息
    property string warningShowText

    function warningSignalChanged(msgSignal)
    {
        if(msgSignal === warningShowText)
        {
            return;
        }

        if("当前报警:" === msgSignal)
        {
            warningShowText = msgSignal;
            warningBack.visible = false
            warnningTest.visible = false;
            sequentialAnimation.stop();
        }
        else
        {
            warningShowText = msgSignal;
            warningBack.visible = true
            warnningTest.visible = true;
            m_contentWidth = warnningTest.contentWidth
            sequentialAnimation.restart();
        }
    }



    Text{
        anchors.centerIn: parent
        font.pixelSize: 40
        font.bold: true
        text: warningShowText
    }

    Rectangle{      // 报警部分
        id:warningBack
        anchors.left: parent.left
        anchors.leftMargin: 5
        anchors.top: parent.top
        anchors.topMargin: 5
        width: 820
        height: 140
        clip:true
        color: "gold"
        // color: "red"

        Text{
            id:warnningTest
            width : parent.width
            height : parent.height
            y:10
            // anchors.verticalCenter: parent.verticalCenter
            horizontalAlignment: Text.AlignLeft
            font.pixelSize: 120
            font.bold: true
            color: "red"
            text:warningShowText
        }

        SequentialAnimation {
            id: sequentialAnimation
            loops: Animation.Infinite // 无限循环
            running: true

            // 从当前位置移动到 -width 的位置
            NumberAnimation {
                target: warnningTest
                properties: "x"
                from: warnningTest.width;
                to: -warnningTest.contentWidth
                duration: 5000 // 持续时间5000毫秒
                easing.type: Easing.Linear // 线性插值
            }

            // 瞬间跳回原点
            NumberAnimation {
                target: warnningTest
                properties: "x"
                to: 0
                duration: 0 // 瞬间完成
            }
        }

    }

    enter: Transition {
        SequentialAnimation
        {
            NumberAnimation{
                property: "opacity"
                from: 0.0
                to: 1.0
                duration: 400
            }

            PauseAnimation {
                duration: 500
            }
        }
    }

    exit: Transition {
        PropertyAction{
            target: popUp
            property: "y"
            value: popUp.parent.height / 5
        }

    }

}
